package cn.com.callback;

import cn.com.kh.KHDBConfig;
import cn.com.kh.KHUtil;
import cn.com.kh.LogToDB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.com.elite.EliteBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.Util;
import org.json.JSONObject;

/**
 *
 * @Title: apiUnderdelivery
 * @Description:深圳水务系统工单数据下送接口--内部
 * @author: chieh
 * @date 2019-12-11 下午14:12:00
 *
 */

public class apiUnderdelivery implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(apiUnderdelivery.class);
    private static int apiTimeOut = 10000;

    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

        response.setCharacterEncoding("UTF-8");

        String getMethod = request.getMethod();
        log.debug("getMethod:" + getMethod);

        String inData = "";
        String outData = "";
        String dataSourceID = "dataSource";

        BufferedReader iny = null;
        if (getMethod == "GET") {
            inData = list.get(0).get("data");
            log.debug("原始Get请求参数:" + inData);
        } else {
            InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
            iny = new BufferedReader(reader);
            String line;
            while ((line = iny.readLine()) != null) {
                inData += line;
            }
            log.debug("原始Post请求参数:" + inData);
        }

        try {
            // 调用处理信息
            JSONObject inObject = new JSONObject(inData);
            log.debug("处理前的Json：" + inObject.toString());

            String sys_source = GetJV(inObject, "sys_source");
            String sys_flag = GetJV(inObject, "sys_flag");//1下送2处理3回访
            String commitId = GetJV(inObject, "commitId");
            String workorderid = GetJV(inObject, "workorderid");
            String handlingopinions = GetJV(inObject, "handlingopinions");
            String type = GetJV(inObject, "type");//光明三高 工单类型映射的type 用于接口地址
            log.debug("解析信息- sys_source：" + sys_source + 'workorderid：' + workorderid);

            if (sys_source == 'JT' && sys_flag == '1') {//集团下送1
                def countresult = eliteBean.chaxun_sql("select count(w.Workorderstepstatus) as count from TABCswgdmerge t LEFT JOIN Workorderstep3 w on t.Relation_ID=w.WORKORDER_GUID WHERE 1=1 and w.Workorderstepstatus='BACK' and t.workorderid = '" + workorderid + "' AND t.rangecodearea = '" + sys_source + "'", "dataSource");
                def count = countresult.get(0).get("count");
                log.debug("是否回退:" + count);
                List list = new ArrayList();
                if (count == 0) {//新增的单，无回退过操作，Nextstepname=1
                    list = eliteBean.chaxun_sql("SELECT NULL AS TaskCode,NULL AS Thisstepname,1 AS Nextstepname,s.OPERATORID AS CommitId,workorderreceiver AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,keyword AS ImportantKey,rangecodewater AS RangeCode,sensitive AS SensitivityTypeCode,registerbusiness3 AS RequestCategory,a.Code_Name + '/' + b.Code_Name + '/' + c.Code_Name AS RequestCategoryName,problemdescription AS Content,wateraddress AS Address,s.OPERATORID AS ReceptionPersonCode,usercode AS RequestUserCode,username AS RequestUserName,usermobile AS Phone,opinion AS Suggest,CONVERT (VARCHAR(100), datelimit, 20) AS DateLimit,case when registerdate='' or registerdate is null then  CONVERT (VARCHAR (100),	getdate(),20) else CONVERT (VARCHAR (100),	registerdate,20)  end  AS RegisterDate,s.OPERATORID AS RegisterCode,registrantname AS Register,operationsource AS SourceType,case when registerdate='' or registerdate is null then  CONVERT (VARCHAR (100),	getdate(),20) else CONVERT (VARCHAR (100),	registerdate,20)  end  AS RequestDate,CASE WHEN isnoresolve = '' OR isnoresolve IS NULL THEN 0 ELSE isnoresolve END AS IsNoResolve, emergencyrepair AS EmergencyRepair,isovertime AS IsOverTime,smsreceiver AS ReceiveId,smstel AS Phones,smscontent AS MessgeConten,isdoortodoor AS IsDoorToDoor,userphone AS Mobile,linkname AS CustomerName,isvalidity AS IsValidity,isautoreturnvisit AS IsAutoReturnVisit,'' AS VolumeCode,'' AS VolumeId,'' AS AttachmentUrl,NULL AS AttachItems,estatename as community,userpointtypeid FROM TABCswgdmerge t LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '一级业务类型') a ON a.Code_ID = t.registerbusiness1 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '二级业务类型') b ON b.Code_ID = t.registerbusiness2 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '三级业务类型') c ON c.Code_ID = t.registerbusiness3 left join (select top 1 * from  WorkOrderStep3 ORDER BY MODIFIEDDATE desc) ws on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on t.registrantname=s.OPERATORNAME WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                    log.debug("SQL获取数据:" + list);
                    outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
                    log.debug("outData获取数据:" + outData);
                    JSONObject outData2 = new JSONObject(outData);
                    def ucisid = GetJV(outData2.getJSONObject("data"), "jsonData");
                    log.debug("ucisid获取数据:" + ucisid);
                    //更新tabc表本地对应ucis的标识uciswordid
                    if (ucisid != '') {
                        eliteBean.update("update TABCswgdmerge set uciswordid='" + ucisid + "' WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                    }
                } else {//回退过的单,再次下送Nextstepname=3
                    list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,NULL AS Thisstepname,3 AS Nextstepname,s.OPERATORID AS CommitId,workorderreceiver AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,keyword AS ImportantKey,rangecodewater AS RangeCode,sensitive AS SensitivityTypeCode,registerbusiness3 AS RequestCategory,a.Code_Name + '/' + b.Code_Name + '/' + c.Code_Name AS RequestCategoryName,problemdescription AS Content,wateraddress AS Address,s.OPERATORID AS ReceptionPersonCode,usercode AS RequestUserCode,username AS RequestUserName,usermobile AS Phone,opinion AS Suggest,CONVERT (VARCHAR(100), datelimit, 20) AS DateLimit,case when registerdate='' or registerdate is null then  CONVERT (VARCHAR (100),	getdate(),20) else CONVERT (VARCHAR (100),	registerdate,20)  end AS RegisterDate,s.OPERATORID AS RegisterCode,registrantname AS Register,operationsource AS SourceType,case when registerdate='' or registerdate is null then  CONVERT (VARCHAR (100),	getdate(),20) else CONVERT (VARCHAR (100),	registerdate,20)  end AS RequestDate,CASE WHEN isnoresolve = '' OR isnoresolve IS NULL THEN 0 ELSE isnoresolve END AS IsNoResolve, emergencyrepair AS EmergencyRepair,isovertime AS IsOverTime,smsreceiver AS ReceiveId,smstel AS Phones,smscontent AS MessgeConten,isdoortodoor AS IsDoorToDoor,userphone AS Mobile,linkname AS CustomerName,isvalidity AS IsValidity,isautoreturnvisit AS IsAutoReturnVisit,'' AS VolumeCode,'' AS VolumeId,'' AS AttachmentUrl,NULL AS AttachItems,estatename as community,userpointtypeid FROM TABCswgdmerge t LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '一级业务类型') a ON a.Code_ID = t.registerbusiness1 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '二级业务类型') b ON b.Code_ID = t.registerbusiness2 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '三级业务类型') c ON c.Code_ID = t.registerbusiness3 left join (select top 1 * from  WorkOrderStep3 ORDER BY MODIFIEDDATE desc) ws on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on t.registrantname=s.OPERATORNAME WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                    outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
                    log.debug("outData获取数据:" + outData);

                    JSONObject outData2 = new JSONObject(outData);
                    def ucisid = GetJV(outData2.getJSONObject("data"), "jsonData");
                    log.debug("ucisid获取数据:" + ucisid);
                }
            }

            if (sys_source == 'JT' && sys_flag == '2') {//集团处理2
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,NULL AS Thisstepname,4 AS Nextstepname,s.OPERATORID AS CommitId,workorderreceiver AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,registerbusiness3 AS RequestCategory,a.Code_Name + '/' + b.Code_Name + '/' + c.Code_Name AS Requestcategoryname,handledescription AS Dealwithresult,responsibleperson AS Dutypersoncode,CONVERT (VARCHAR (100),arriveddate,20) AS Arrivaldate,CONVERT (VARCHAR (100),finishtime,20) AS Dealenddate,CONVERT (VARCHAR (100),	doordate,20) AS preconcerteddate,handlerby AS Operator,handlerphone AS Dealpersonphoneno,s.OPERATORID AS Beginregisterpersoncode,NULL AS Registertime,CONVERT (	VARCHAR (100),	isovertime,	20) as Isovertime,CONVERT (VARCHAR (100),isdoortodoor,20) as isdoortodoor,CONVERT (VARCHAR (100),starttime,20) AS Dealstartdate,failurecause AS Failurecause,CONVERT (VARCHAR(100), firstarrivaldate, 20) as Firstarrivaldate,remarks as dealdesc  FROM TABCswgdmerge t LEFT JOIN (SELECT	* FROM	C_CodeTables WHERE	Use_Type = '一级业务类型') a ON a.Code_ID = t.registerbusiness1 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '二级业务类型') b ON b.Code_ID = t.registerbusiness2 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '三级业务类型') c ON c.Code_ID = t.registerbusiness3 left join (select top 1 * from  WorkOrderStep3 ORDER BY MODIFIEDDATE desc) ws on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on t.registercodename=s.OPERATORNAME WHERE  workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);

                // 获取工单的业务来源-线上平台与数字化城管的单不需要回访，直接结案；需更新处理步骤的数据
                def getYwlySelectSQL = eliteBean.chaxun_sql("select Relation_ID as Relation_ID,operationsource as servicesource,rangecodearea as rangecodearea from TABCswgdmerge where workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", dataSourceID);
                log.debug("查询获取业务来源sql:" + getYwlySelectSQL);

                String Relation_ID = null;
                String servicesource = null;
                String rangecodearea = null;
                Relation_ID = getYwlySelectSQL.get(0).get("Relation_ID");
                servicesource = getYwlySelectSQL.get(0).get("servicesource");
                rangecodearea = getYwlySelectSQL.get(0).get("rangecodearea");
                log.debug("查询获取业务来源是：" + servicesource + ",区域：" + rangecodearea + ",Relation_ID：" + Relation_ID);
                //15 线上平台-自助终端  16 线上平台-微信公众号  17 线上平台-网厅  18 线上平台-i深圳   4 数字化城管网站
                if (rangecodearea == 'JT' && (servicesource == "4" || servicesource == "15" || servicesource == "16" || servicesource == "17" || servicesource == "18")) {
                    String[] data2 = new String[4];
                    data2[0] = "insert into TABCswgdmerge_His select NEWID(), * from TABCswgdmerge where Relation_ID = '" + Relation_ID + "'";
                    data2[1] = "update TABCswgdmerge set workorderstatus='5'  where Relation_ID = '" + Relation_ID + "'";
                    data2[2] = "Update Objective Set Handlegroup_Id = 'CW0001', Handleby_Id = 'SELITE', Objectivestatus = 'CLOSE', Map_Id = Map_Id, Curstep_Id_Map = '0DKTUC', Modifiedby = 'SELITE', Modifieddate = Getdate() Where Objective_Guid = '" + Relation_ID + "'";
                    data2[3] = "Update Elitetask Set Handlegroup_Id = 'CW0001', Handleby_Id = 'SELITE', Map_Id = Map_Id, Curstepstatus = 'END', Curstep_Id = '0DKTUC', Curstep_Id_Map = '0DKTUC', Objectivesubstatus = Objectivesubstatus, Modifiedby = 'SELITE', Modifieddate = Getdate() Where Objective_Guid = '" + Relation_ID + "'";
                    log.debug("判断数字化/线上平台工单结案进行下一步处理SQL:" + data2.toString());
                    int[] dataresult2 = eliteBean.updateBatch(data2, dataSourceID);
                    log.debug("判断数字化/线上平台工单结案进行下一步处理SQL结果:" + dataresult2.toString());
                }

            }
            if (sys_source == 'JT' && sys_flag == '3') {//集团回访3
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 5, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,s.OPERATORID AS Thisstepname,5 AS Nextstepname,s.OPERATORID AS CommitId,workorderreceiver AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,s.OPERATORID  AS FeedbackPersonCode,CONVERT (VARCHAR(100), feedbacktime, 20) AS FeedBackDate,userreflect AS UserResponse,serviceattitude AS ServiceManner,quality AS ServiceQuality,satisfaction AS ApproveDegree,feedback AS ElseSuggest,empattire AS Appearance, handledescription AS Dealwithresult,handlebusiness3 AS RequestCategory,a.Code_Name + '/' + b.Code_Name + '/' + c.Code_Name AS Requestcategoryname FROM TABCswgdmerge t LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '一级业务类型') a ON a.Code_ID = t.handlebusiness1 LEFT JOIN (SELECT * FROM C_CodeTables WHERE	Use_Type = '二级业务类型') b ON b.Code_ID = t.handlebusiness2 LEFT JOIN (SELECT	*FROM	C_CodeTables WHERE	Use_Type = '三级业务类型' ) c ON c.Code_ID = t.handlebusiness3 left join (select top 1 * from  WorkOrderStep3 ORDER BY MODIFIEDDATE desc) ws on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on t.returnname=s.OPERATORNAME WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
            }
            /*
             * UCIS: 【回退】【返工】【催单】【强制结束】【取消】【激活】【委托】【延时】
             * 申请退单 6
             * 任务返工 7
             * 任务督办 8
             * 结束任务接口 9
             * 取消任务接口 10
             * 激活任务 11
             * 委托任务  12
             * 任务延时 13
             */
            if (sys_source == 'JT' && sys_flag == '6') {//申请退单 6
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,NULL AS Thisstepname,'" + sys_flag + "' AS Nextstepname,s.OPERATORID AS CommitId,'' AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,'' as ActiveStep,'' as VolumeId,'' as VolumeCode FROM TABCswgdmerge t left join (select top 1 * from  WorkOrderStep3 where WORKORDERSTEPSTATUS='BACK' ORDER BY MODIFIEDDATE desc) ws  on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on s.STAFF_ID=ws.OLDHANDLEBY_ID WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
            }
            //任务返工 7 暂时按退单处理
            if (sys_source == 'JT' && sys_flag == '8') {//任务督办 8
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,NULL AS Thisstepname,'" + sys_flag + "' AS Nextstepname,s.OPERATORID AS CommitId,'' AS ReceiveOperatorId,case when '" + handlingopinions + "'='' or '" + handlingopinions + "' is not null then '" + handlingopinions + "' else ws.COMMENTS end  AS DealRemark,'' as ActiveStep,'' as VolumeId,'' as VolumeCode FROM TABCswgdmerge t left join (select top 1  * from  WorkOrderStep3 where WORKORDER_GUID in (select Relation_ID from TABCswgdmerge where workorderid='" + workorderid + "') ORDER BY 	MODIFIEDDATE DESC) ws  on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on s.STAFF_ID=ws.OLDHANDLEBY_ID WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
            }

            if (sys_source == 'JT' && sys_flag == '13') {//任务延时 13

                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT case when uciswordid is not null or uciswordid!='' then uciswordid else workorderid end AS TaskCode,NULL AS Thisstepname,'" + sys_flag + "' AS Nextstepname,s.OPERATORID AS CommitId,'' AS ReceiveOperatorId,ws.COMMENTS AS DealRemark,'' as ActiveStep,'' as VolumeId,'' as VolumeCode FROM TABCswgdmerge t left join (select top 1 * from  WorkOrderStep3 where WORKORDERSTEPSTATUS='BACK' ORDER BY MODIFIEDDATE desc) ws  on t.Relation_ID=ws.WORKORDER_GUID LEFT JOIN sw_opeartor s on s.STAFF_ID=ws.OLDHANDLEBY_ID WHERE workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDJTUnderdelivery(eliteBean, sys_source, sys_flag, list);
            }

            //根据获取业务类型判断下送供水排水接口
            def gm_ispsgs = "";
            if (sys_source == 'GM') {
                def handlebusiness3result = eliteBean.chaxun_sql("SELECT cc.gm_ispsgs as gm_ispsgs FROM	TABCswgdmerge t left join  (select Code_ID,gm_ispsgs from C_CodeTables where use_type='三级业务类型') cc on cc.Code_ID=t.registerbusiness3  WHERE	workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", dataSourceID);
                gm_ispsgs = handlebusiness3result.get(0).get("gm_ispsgs");
                log.debug("光明接口类型:" + gm_ispsgs);
            }
            if (sys_source == 'GM' && sys_flag == '1') {//光明下送1
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT workorderid AS customserviceid,	'PDA调度中心' AS acceptstation,	registrantname AS acceptpeople,	CONVERT(varchar(100), registerdate, 20) AS accepttime,	CONVERT(varchar(100), datelimit, 20) AS cometime_plan,	cc.Code_Name AS reportsource,	a.Code_Name AS missiontype,	username AS customid,	linkname AS reportpeople,	userphone AS tel,	usermobile AS mobile,	registerbusiness2 AS reporttype,	registerbusiness3 AS reportcontent,	rangecodewater AS gdssfw,	wateraddress AS happenaddr,	problemdescription AS acceptremark,	workorderreceiver AS pdaid, shifttype As type,userpointtypeid as  userPointTypeid FROM	TABCswgdmerge t LEFT JOIN (select Code_ID ,Code_Name from C_CodeTables where use_type='敏感类型') a on a.Code_ID=t.sensitive LEFT JOIN C_CodeTables cc on cc.Code_ID=t.operationsource and use_type='业务来源' WHERE	workorderid = '" + workorderid + "' AND rangecodearea = '" + sys_source + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDGMUnderdelivery(eliteBean, sys_source, sys_flag, gm_ispsgs, list);
            }
            if (sys_source == 'GM' && sys_flag == '10') {//光明延期通过
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 10, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("select 1 as type,'true' as result,workorderid as customserviceid,'延期申请通过' as replyremark,s.staffname as replyoperator,CONVERT(varchar(100), o.modifieddate, 20) as replytime from objective o LEFT JOIN staff s on s.staff_id=o.handleby_id where workorderid='" + workorderid + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDGMGetReplyResult(eliteBean, sys_source, sys_flag, gm_ispsgs, list);
            }
            if (sys_source == 'GM' && sys_flag == '11') {//光明延期不通过
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 11, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("select '1' as type,'false' as result,workorderid as customserviceid,'延期申请不通过' as replyremark,s.staffname as replyoperator,CONVERT(varchar(100), o.modifieddate, 20) as replytime from objective o LEFT JOIN staff s on s.staff_id=o.handleby_id where workorderid='" + workorderid + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDGMGetReplyResult(eliteBean, sys_source, sys_flag, gm_ispsgs, list);
            }
            if (sys_source == 'GM' && sys_flag == '3') {//光明回访审核通过
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 12, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("SELECT '2' AS type,'true' AS result,t.workorderid AS customserviceid,'回访审核通过' AS replyremark,s.staffname AS replyoperator,CONVERT (	VARCHAR (100),	o.modifieddate,	20) AS replytime,a.code_name AS feedback,b.code_name AS attitude,c.code_name AS serquality,t.returnname AS returnperson,CONVERT (	VARCHAR (100),	t.feedbacktime,	20) AS returntime,d.code_name AS Satisfaction,e.code_name AS employeeattire FROM objective o LEFT JOIN TABCswgdmerge t ON t.Relation_ID = o.objective_guid  LEFT JOIN staff s ON s.staff_id = o.handleby_id LEFT JOIN (select code_id,code_name from c_codetables where use_type='满意度') a on a.code_id=t.userreflect LEFT JOIN (select code_id,code_name from c_codetables where use_type='满意度') b on b.code_id=t.serviceattitude LEFT JOIN (select code_id,code_name from c_codetables where use_type='满意度') c on c.code_id=t.quality LEFT JOIN (select code_id,code_name from c_codetables where use_type='满意度') d on d.code_id=t.satisfaction LEFT JOIN (select code_id,code_name from c_codetables where use_type='着装度') e on e.code_id=t.empattire WHERE t.workorderid = '" + workorderid + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDGMGetReplyResult(eliteBean, sys_source, sys_flag, gm_ispsgs, list);
            }
            if (sys_source == 'GM' && sys_flag == '6') {//光明回访审核不通过,回访步骤界面退单
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 13, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                List list = new ArrayList();
                list = eliteBean.chaxun_sql("select '2' as type,'false' as result,workorderid as customserviceid,'回访审核不通过' as replyremark,s.staffname as replyoperator,CONVERT(varchar(100), o.modifieddate, 20) as replytime from objective o LEFT JOIN staff s on s.staff_id=o.handleby_id where workorderid='" + workorderid + "'", "dataSource");
                log.debug("SQL获取数据:" + list);
                outData = SWGDGMGetReplyResult(eliteBean, sys_source, sys_flag, gm_ispsgs, list);
            }

            if (sys_source == 'BA' && sys_flag == '1') {//宝安下送1
                outData = SWGDBAUnderdelivery(eliteBean, sys_source, sys_flag, type, workorderid);
            }
            if (sys_source == 'BA' && sys_flag == '3') {//宝安回訪3
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 5, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                outData = "{\"code\":\"1\",\"message\":\"宝安回訪调用成功\",\"data\":\"" + updatesamp + "\"}";
            }
            if (sys_source == 'BA' && sys_flag == '6') {//宝安回访 回退2
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 3, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                //查询type
                def typeresult = eliteBean.chaxun_sql("select top 1 c.ba_sgwyid as type from objective o left  join TABCswgdmerge t ON t.Relation_ID = o.objective_guid LEFT JOIN C_CodeTables c on t.registerbusiness3=c.Code_ID and use_type='三级业务类型'  AND Use_Status = '1' where 1=1 and o.workorderid= '" + workorderid + "'", dataSourceID);
                type = typeresult.get(0).get("type");
                log.debug("SQL获取数据type:" + type);
                outData = SWGDBAUnderdelivery(eliteBean, sys_source, sys_flag, type, workorderid);
            }
            if (sys_source == 'BA' && sys_flag == '10') {//宝安延期申请通过 10
                def updatesamp = eliteBean.update("Update Tabcswgdmerge Set Workorderstatus = 10, Modifydate = GETDATE() WHERE workorderid = '" + workorderid + "'", "dataSource");
                //查询type
                def typeresult = eliteBean.chaxun_sql("select top 1 c.ba_sgwyid as type from objective o left  join TABCswgdmerge t ON t.Relation_ID = o.objective_guid LEFT JOIN C_CodeTables c on t.registerbusiness3=c.Code_ID and use_type='三级业务类型'  AND Use_Status = '1' where 1=1 and o.workorderid= '" + workorderid + "'", dataSourceID);
                type = typeresult.get(0).get("type");
                log.debug("SQL获取数据type:" + type);
                outData = SWGDBAUnderdelivery(eliteBean, sys_source, sys_flag, type, workorderid);
            }


        } catch (Exception e) {
            log.error("接口处理异常" + e.getMessage());
            // 失败返回
            outData = "{\"resultcode\":\"0\",\"resultmessage\":\"处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):2\",\"data\":[]}";

        }
        log.debug("完成返回结果:" + outData);

        return outData;
    }

    //调用集团UCIS接口
    public static String SWGDJTUnderdelivery(EliteBean eliteBean, String sys_source, String workorderid, ArrayList list) {
        long startTime = System.currentTimeMillis();

        String json = null;
        String reJson = null;
        try {
            //获取总行数
            def listsize = list.size();
            log.debug("sql获取总条数:" + listsize);
            def reJoson = Util.getJsonFromList(list);
            //log.debug("reJoson"+reJoson);

            json = reJoson.replace('\"null\"', "null");
            json = json.replace('\""', "null");
            json = json.replace('[', '');
            json = json.replace(']', '');


            //json = URLEncoder.encode(json, "utf-8");
            json = "receiveJsonStr=" + json + "";

            log.debug("json:" + json);
            //接口调用
            def returnMsg = "";
            Map headMap = new HashMap();
            headMap.put("Content-Type", "application/x-www-form-urlencoded");
            String charset = "utf-8";

            // 将工单接口调用超时的时间作为配置项
            int timeout = apiTimeOut;
            String api_TimeOut = KHDBConfig.getParamConfig(eliteBean, "API_TimeOut_JTWO");
            try {
                timeout = KHUtil.isNull(api_TimeOut) ? 10 : Integer.parseInt(api_TimeOut);
            } catch (Exception e) {
                log.warn("获取调用超时时间配置项异常,将使用全局默认值:" + apiTimeOut, e);
            }

            def enablessLfag = 0;
            String url = "http://10.200.2.120:80/WebServices/WSWorkFlow.asmx/ReceiveCrmOrders";
            log.debug("url=" + url);

            //接口调用
            def jsonBack = Util.doHttpPostUseHead(url, json, charset, timeout, enablessLfag, headMap);
            log.debug("jsonBack1:" + jsonBack);

            jsonBack = Util.Transform(jsonBack); //去命令空间
            jsonBack = jsonBack.replace('<string>', '');
            jsonBack = jsonBack.replace('</string>', '');

            // 包装拼接返回JSONObject
            reJson = "{\"resultcode\":\"1\",\"resultmessage\":\"集团工单处理完成、调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":" + jsonBack + "}";

        } catch (Exception e) {
            reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"集团工单处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":{}}";
        } finally {
            LogToDB.toDB(eliteBean, "dataSource", "[工单]集团工单", "apiUnderdelivery", json, reJson, (System.currentTimeMillis() - startTime).toString(), workorderid);
        }

        return reJson;
    }

    //调用光明慧集下送接口
    public static String SWGDGMUnderdelivery(EliteBean eliteBean, String sys_source, String workorderid, String gm_ispsgs, ArrayList list) {
        long startTime = System.currentTimeMillis();

        String json = null;
        String reJson = null;
        try {
            //获取总行数
            def listsize = list.size();
            log.debug("sql获取总条数:" + listsize);
            def reJoson = Util.getJsonFromList(list);
            log.debug("reJoson" + reJoson);

            json = reJoson.replace('\"null\"', "null");
            json = json.replace('\""', "null");
            json = json.replace('[', '');
            json = json.replace(']', '');

            json = "hotinputinfo=" + json + "";
            log.debug("报文:" + json);
            //接口调用
            def returnMsg = "";
            Map headMap = new HashMap();
            headMap.put("Content-Type", "text/plain");
            def charset = "utf-8";

            // 将工单接口调用超时的时间作为配置项
            int timeout = apiTimeOut;
            String api_TimeOut = KHDBConfig.getParamConfig(eliteBean, "API_TimeOut_JTWO");
            try {
                timeout = KHUtil.isNull(api_TimeOut) ? 10 : Integer.parseInt(api_TimeOut);
            } catch (Exception e) {
                log.warn("获取调用超时时间配置项异常,将使用全局默认值:" + apiTimeOut, e);
            }

            def enablessLfag = 0;
            def url = "";
            if (gm_ispsgs == 'ps') {//排水接口
                //url="http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.129.66:25085/PAISHUI_Hotline/HUGEGISInterface.asmx/GetHotlineInfo";
                url = "http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.2.124:25085/PAISHUI_Hotline/HUGEGISInterface.asmx/GetHotlineInfo";
            } else {//供水接口
                url = "http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.1.92:25087/GetHotLine/HUGEGISInterface.asmx/GetHotlineInfo";
            }
            log.debug(gm_ispsgs + "--url=" + url);

            //接口调用
            def jsonBack = Util.doHttpPostUseHead(url, json, charset, timeout, enablessLfag, headMap);
            log.debug("jsonBack1:" + jsonBack);

            jsonBack = Util.Transform(jsonBack); //去命令空间
            log.debug("jsonBack2:" + jsonBack);
            jsonBack = jsonBack.replace('<string>', '');
            jsonBack = jsonBack.replace('</string>', '');

            long endTime = System.currentTimeMillis();
            // 包装拼接返回JSONObject
            reJson = "{\"resultcode\":\"1\",\"resultmessage\":\"光明工单处理完成、调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":" + jsonBack + "}";

        } catch (Exception e) {
            long endTime = System.currentTimeMillis();
            reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"光明工单处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":{}}";
        } finally {
            LogToDB.toDB(eliteBean, "dataSource", "[工单]光明慧集下送", "apiUnderdelivery", json, reJson, (System.currentTimeMillis() - startTime).toString(), workorderid);
        }

        return reJson;
    }

    //调用光明慧集接口
    public static String SWGDGMGetReplyResult(EliteBean eliteBean, String sys_source, String workorderid, String gm_ispsgs, ArrayList list) {
        long startTime = System.currentTimeMillis();

        String json = null;
        String reJson = null;
        try {
            //获取总行数
            def listsize = list.size();
            log.debug("sql获取总条数:" + listsize);
            def reJoson = Util.getJsonFromList(list);
            log.debug("reJoson" + reJoson);

            json = reJoson.replace('\"null\"', "null");
            json = json.replace('\""', "null");
            json = json.replace('[', '');
            json = json.replace(']', '');
            json = "resultInfo=" + json + "";
            log.debug("json:" + json);
            //接口调用
            def returnMsg = "";
            Map headMap = new HashMap();
            headMap.put("Content-Type", "text/plain");
            def charset = "utf-8";

            // 将工单接口调用超时的时间作为配置项
            int timeout = apiTimeOut;
            String api_TimeOut = KHDBConfig.getParamConfig(eliteBean, "API_TimeOut_JTWO");
            try {
                timeout = KHUtil.isNull(api_TimeOut) ? 10 : Integer.parseInt(api_TimeOut);
            } catch (Exception e) {
                log.warn("获取调用超时时间配置项异常,将使用全局默认值:" + apiTimeOut, e);
            }

            def enablessLfag = 0;
            def url = "";
            if (gm_ispsgs == 'ps') {//排水接口
                //url="http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.129.66:25085/PAISHUI_Hotline/HUGEGISInterface.asmx/GetReplyResult";
                url = "http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.2.124:25085/PAISHUI_Hotline/HUGEGISInterface.asmx/GetReplyResult";
            } else {//供水接口
                url = "http://138.0.0.65:8020/EliteGeneralHttpTask/GeneralService/apiTest?url=http://172.19.1.92:25087/GetHotLine/HUGEGISInterface.asmx/GetReplyResult";
            }
            log.debug(gm_ispsgs + "--url=" + url);

            //接口调用
            def jsonBack = Util.doHttpPostUseHead(url, json, charset, timeout, enablessLfag, headMap);
            log.debug("jsonBack1:" + jsonBack);

            jsonBack = Util.Transform(jsonBack); //去命令空间
            log.debug("jsonBack2:" + jsonBack);
            jsonBack = jsonBack.replace('<string>', '');
            jsonBack = jsonBack.replace('</string>', '');

            long endTime = System.currentTimeMillis();
            // 包装拼接返回JSONObject
            reJson = "{\"resultcode\":\"1\",\"resultmessage\":\"光明工单审核处理完成、调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":" + jsonBack + "}";

        } catch (Exception e) {
            long endTime = System.currentTimeMillis();
            reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"光明审核工单处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":{}}";
        } finally {
            LogToDB.toDB(eliteBean, "dataSource", "[工单]光明慧集回复", "apiUnderdelivery", json, reJson, (System.currentTimeMillis() - startTime).toString(), workorderid);
        }

        return reJson;
    }

    //调用宝安三高下送接口
    public static String SWGDBAUnderdelivery(EliteBean eliteBean, String sys_source, String sys_flag, String type, String workorderid) {
        long startTime = System.currentTimeMillis();

        String json = null;
        String reJson = null;
        try {
            log.debug("工单分类:" + type);//--902

            String getSelectSQL = eliteBean.chaxun_sql("select s.LOGINNAME as creator,o.createddate as createTime,a.Code_Name + '/' + b.Code_Name + '/' + c.Code_Name as title,t.problemdescription as content,t.wateraddress as address,case when t.emergencyrepair=1 then 2 else 1 end as urgencyLevel,'YUEQI' as disposeLevel,t.registerdate as  appointStartTime,t.datelimit as appointEndTime,t.workorderreceiver as nextOperator,d.Code_Name AS nextOrganization,t.linkname as linkname,t.usercode as usercode,t.username as username,t.userphone as userphone,t.usermobile as usermobile,'0' as isPlan,o.workorderid as origin,o.comments as remark,'' as parentId,'' as batchId,'' as bizDataset  from TABCswgdmerge t LEFT JOIN objective o on t.Relation_ID=o.objective_guid  LEFT JOIN (SELECT * FROM	C_CodeTables WHERE	Use_Type = '一级业务类型') a ON a.Code_ID = t.registerbusiness1 LEFT JOIN (SELECT * FROM C_CodeTables WHERE	Use_Type = '二级业务类型') b ON b.Code_ID = t.registerbusiness2 LEFT JOIN (SELECT * FROM C_CodeTables WHERE	Use_Type = '三级业务类型') c ON c.Code_ID = t.registerbusiness3 LEFT JOIN (SELECT * FROM C_CodeTables WHERE Use_Type = '受理部门' and Code_Desc='BA') d ON d.Code_ID = t.rangecodewater left join staff s on s.staff_id=o.createdby where o.workorderid= '" + workorderid + "'", "dataSource");
            log.debug("查询当前同步的工单是否已经存在 SQL:" + getSelectSQL + " 结果数量:" + getSelectSQL.size());

            if (getSelectSQL.size() > 0) {

                String creator, createTime, title, content, address, urgencyLevel, disposeLevel, appointStartTime, appointEndTime, nextOperator, nextOrganization, otherOperator, isPlan, origin, remark, parentId, batchId, BIZ_TYPE, USER_NO, USER_NAME, LINKMAN, CONTACT_NUMBER, OTHER_NUMBER, COMMUNITY = "";

                creator = getSelectSQL.get(0).get("creator");//创建人--cisktytest
                //creator="cisktytest";
                createTime = getSelectSQL.get(0).get("createTime");//创建时间---2020/7/14 15:48:23
                title = getSelectSQL.get(0).get("title");//工单标题--报修/供水管道/市政供水管滴漏
                content = getSelectSQL.get(0).get("content");//工单内容-- 市政水管爆裂、漏水。（测试单）
                address = getSelectSQL.get(0).get("address");//工单地址--ddd
                urgencyLevel = getSelectSQL.get(0).get("urgencyLevel");//紧急程度--1：一般；2：紧急；3：非常紧急
                disposeLevel = getSelectSQL.get(0).get("disposeLevel");//处理级别-0:无; :当天; YUEQI:约期; 120:2小时; 240:4小时; 480:8小时; 1440:24小时; 1DAY:1天; 2DAY:2天; 3DAY:3天;
                appointStartTime = getSelectSQL.get(0).get("appointStartTime");//预约开始时间--当处理级别为约期时必填
                appointEndTime = getSelectSQL.get(0).get("appointEndTime");//预约结束时间--当处理级别为约期时可填
                if (appointStartTime == "null") {
                    appointStartTime = "";
                }
                if (appointEndTime == "null") {
                    appointEndTime = "";
                }
                nextOperator = getSelectSQL.get(0).get("nextOperator");//下一步处理人--用户标识，多个标识用逗号分隔。当需要指定下一步处理人时必填，即接单人。
                nextOrganization = getSelectSQL.get(0).get("nextOrganization");//下一步处理组织--当需要指定下一步处理组织时必填，即接单组织

                isPlan = getSelectSQL.get(0).get("isPlan");//是否计划工单--0:否；1:是
                origin = getSelectSQL.get(0).get("origin");//工单来源标识-记录来源的唯一标识，一般是客户端生成工单的唯一业务编号
                remark = getSelectSQL.get(0).get("remark");//备注
                parentId = getSelectSQL.get(0).get("parentId");//父工单编号
                batchId = getSelectSQL.get(0).get("batchId");//工单批次号

                BIZ_TYPE = title;//业务类型
                USER_NO = getSelectSQL.get(0).get("usercode");//用户编号
                USER_NAME = getSelectSQL.get(0).get("username");//用户名
                LINKMAN = getSelectSQL.get(0).get("linkname");//联系人
                CONTACT_NUMBER = getSelectSQL.get(0).get("userphone");//联系电话
                OTHER_NUMBER = getSelectSQL.get(0).get("usermobile");//其他联系电话

                json = "{\"type\":\"" + type + "\",\"creator\":\"" + creator + "\",\"createTime\":\"" + createTime + "\",\"title\":\"" + title + "\",\"content\":\"" + content + "\",\"address\":\"" + address + "\",\"gisExtent\":{\"type\":\"CUSTOM\",\"coordinates\":[0,0]},\"urgencyLevel\":\"" + urgencyLevel + "\",\"disposeLevel\":\"" + disposeLevel + "\",\"appointStartTime\":\"" + appointStartTime + "\",\"appointEndTime\":\"" + appointEndTime + "\",\"nextOperator\":\"" + nextOperator + "\",\"nextOrganization\":\"" + nextOrganization + "\",\"otherOperator\":\"" + otherOperator + "\",\"isPlan\":\"" + isPlan + "\",\"origin\":\"" + origin + "\",\"remark\":\"" + remark + "\",\"extend\":\"{\\\"isDoorService\\\":\\\"1\\\",\\\"UserPointType\\\":0}\",\"parentId\":\"" + parentId + "\",\"batchId\":\"" + batchId + "\",\"bizDataset\":[{\"table\":\"GD_FORM_YHTS\",\"fields\":[{\"name\":\"BIZ_TYPE\",\"value\":\"" + BIZ_TYPE + "\"},{\"name\":\"USER_NO\",\"value\":\"" + USER_NO + "\"},{\"name\":\"USER_NAME\",\"value\":\"" + USER_NAME + "\"},{\"name\":\"LINKMAN\",\"value\":\"" + LINKMAN + "\"},{\"name\":\"CONTACT_NUMBER\",\"value\":\"" + CONTACT_NUMBER + "\"},{\"name\":\"OTHER_NUMBER\",\"value\":\"" + OTHER_NUMBER + "\"},{\"name\":\"COMMUNITY\",\"value\":\"\"}]}]}";
                log.debug("报文:" + json);
                json = json.replace('\"null\"', "null");
                log.debug("处理后的报文:" + json);

                def szhtok;
                def szhtokresult = eliteBean.chaxun_sql("select PARAMETERVALUE from SYSC_PARAMETER where PARAMETER_ID = 'BAWYSG' and MODIFIEDDATE>GETDATE()", "dataSource");
                if (szhtokresult.size() > 0) {
                    szhtok = szhtokresult.get(0).get("PARAMETERVALUE");
                    log.debug("szhtok:	" + szhtok);
                }
                if (szhtok == null) {
                    szhtok = getCaseTasks(eliteBean);
                }

                //接口调用
                def returnMsg = "";
                Map headMap = new HashMap();
                headMap.put("Content-Type", "application/json");
                headMap.put("X-Appkey", "ls4fcsjIqODUfLVBlQ6NxEFVY8fJDVYb");
                headMap.put("token", szhtok);
                String charset = "utf-8";

                // 将工单接口调用超时的时间作为配置项
                int timeout = apiTimeOut;
                String api_TimeOut = KHDBConfig.getParamConfig(eliteBean, "API_TimeOut_BAWO");
                try {
                    timeout = KHUtil.isNull(api_TimeOut) ? 10 : Integer.parseInt(api_TimeOut);
                } catch (Exception e) {
                    log.warn("获取调用超时时间配置项异常,将使用全局默认值:" + apiTimeOut, e);
                }

                int enablessLfag = 0;

                // String url = "http://10.200.6.92:8087/client_api/ws/v1/types/" + type + "/worksheets/dispatch";
                String url = KHDBConfig.getAPIURL(eliteBean, "BAWY_WSWorkFlow") + "/client_api/ws/v1/types/" + type + "/worksheets/dispatch";
                log.debug("--url=" + url);

                //接口调用
                def getResult = Util.doHttpPostUseHead(url, json, charset, timeout, enablessLfag, headMap);
                log.debug("getResult:" + getResult);

                //解析接口返回信息
                JSONObject jsonObject = new JSONObject(getResult);
                String code = GetJV(jsonObject, "code");
                String data = GetJV(jsonObject, "data");

                JSONObject dataObject;
                log.debug("code:" + code);
                if (code == "0") {
                    dataObject = new JSONObject(data);
                    String id = GetJV(dataObject, "id");
                    log.debug("id:" + id);
                    //绑定关系
                    eliteBean.update("update TABCswgdmerge set uciswordid = '" + id + "' where workorderid = '" + workorderid + "'", "dataSource");
                    // 包装拼接返回JSONObject
                    reJson = "{\"resultcode\":\"1\",\"resultmessage\":\"宝安工单处理完成、调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":\"" + id + "\"}";
                } else {
                    // 包装拼接返回JSONObject
                    reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"宝安工单处理失败、调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":" + getResult + "}";
                }
            } else {
                reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"宝安工单处理失败(工单数据不存在),调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":{}}";
            }

        } catch (Exception e) {
            reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"宝安工单处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):" + (System.currentTimeMillis() - startTime) + "\",\"data\":{}}";
        } finally {
            LogToDB.toDB(eliteBean, "dataSource", "[工单]宝安三高", "apiUnderdelivery", json, reJson, (System.currentTimeMillis() - startTime).toString(), workorderid);
        }

        return reJson;
    }

    // 获取宝安三高Token
    public static String getCaseTasks(EliteBean eliteBean) {
        log.debug("获取宝安三高接口Token...");
        String sysurl = "http://127.0.0.1:8010/EliteGeneralHttpTask/GeneralService/api_Get_WYSGToKen";
        String reJson = Util.doHttpGet(sysurl, "UTF-8", apiTimeOut, 0);
        JSONObject inObject = new JSONObject(reJson);

        // 解析Token返回结果
        String code = GetJV(inObject, "code");
        String data = "";
        if (code == "0") {
            data = GetJV(inObject, "data");
        } else {
            data = null;
        }
        log.debug("获取宝安三高接口Token结果:" + data);
        return data;
    }

    // 解析Json值
    public static String GetJV(JSONObject inJson, String getKey) {
        String Rev_Value = null;
        try {
            Rev_Value = inJson.getString(getKey);
        } catch (Exception e) {
            try {
                Rev_Value = String.valueOf(inJson.getInt(getKey));
            } catch (Exception e1) {
                try {
                    Rev_Value = String.valueOf(inJson.getJSONArray(getKey));
                } catch (Exception e2) {
                    try {
                        Rev_Value = String.valueOf(inJson.getJSONObject(getKey));
                    } catch (Exception e3) {
                        Rev_Value = "";
                    }
                }
            }
        } finally {
            if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
                Rev_Value = "";
            } else {
            }
        }
        return Rev_Value;
    }

}
